<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style>
    body{
        margin: 300px 800px;
    }
    button{
        width: 300px;
        height: 35px;
    }
    div{
        width: 300px;
        height: 50px;
        background: coral;
        line-height: 3;
        text-align: center;
        margin-top: 5px;
    }
    p{
        width: 300px;
        height: 50px;
        background: coral;
        line-height: 3;
        text-align: center;
        margin-top: 5px;
    }
</style>
<body>
<button>获取时间</button>
<div>
    获取当前时间
</div>
<p>123</p>
<script>
    var btn = document.querySelector('button');
    var div = document.querySelector('div');
    btn.onclick = function () {
        div.innerHTML = getDate();
    };
    function getDate() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth();
        var hours = date.getHours();
        var minutes = date.getMinutes();
        var day = date.getDay();
        var arr = ['星期天','星期一','星期二','星期三','星期四','星期五','星期六'];
        return year + '年' + month + '月' + hours + '点' + minutes + '分  ' + arr[day];
    }
    var p = document.querySelector('p');
    p.innerHTML = getDate();
</script>
</body>
</html>